package com.bjtime.hprinter.Fragments.designer

import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bjtime.designer.attributes.ViewAttr
import com.bjtime.designer.view.FViewPager
import com.bjtime.designer.widget.BaseLabelView
import com.bjtime.hprinter.Fragments.attrs.AttsPageAdapter
import com.bjtime.hprinter.R


class Attrs : Fragment{

    constructor()



    companion object {
        fun newInstance(): Attrs {
            return Attrs ()
        }
    }

    private var adapter : AttsPageAdapter? = null
    private var mView   : View? = null
    private var mPager  : FViewPager? = null

    fun setSelect (type : ViewAttr.VIEW_TYPE) {
        when (type) {
            ViewAttr.VIEW_TYPE.BASE     ->      mPager?.setCurrentItem(0, false)
            ViewAttr.VIEW_TYPE.LINE     ->      mPager?.setCurrentItem(1, false)
            ViewAttr.VIEW_TYPE.BARCODE  ->      mPager?.setCurrentItem(2, false)
            ViewAttr.VIEW_TYPE.QRCODE   ->      mPager?.setCurrentItem(3, false)
            ViewAttr.VIEW_TYPE.TEXT     ->      mPager?.setCurrentItem(4, false)
            ViewAttr.VIEW_TYPE.IMAGE     ->      mPager?.setCurrentItem(5, false)
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        adapter =  AttsPageAdapter (getFragmentManager ()!!)
        mView = LayoutInflater.from(context).inflate(R.layout.viewpager_layout_attrs, null)
        mPager = mView!!.findViewById<FViewPager>(R.id.designer_attrs_fpv)
        mPager!!.mCanSlide = false
        mPager!!.adapter = adapter
        mPager!!.setCurrentItem(0)

        return mView
    }

    fun setView (v : BaseLabelView) {
        adapter?.setView (v)
    }

}